<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    li{
      width: 400px;
      height: 50px;
      background-color: #e1e7d3;
      margin-top: 20px;
    }
  </style>
</head>
<body>
  <div id="app">
    a属性改变
    <input type="text" v-model="obj.a">
     -->{{obj.a}}
     <br>
     b属性改变
     <input type="text" v-model="obj.b">
      -->{{obj.b}}
      <br>
    <button @click="arr.push(arr.length+1)">新增数组</button>
    {{arr}}
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const  app = createApp({
      data(){
        return {
          obj: {
            a: 'a属性',
            b: 'b属性'
          },
          arr: [1,2,3,4]
        }
      },
      watch: {
        // 引用类型 需要 深度侦听 定义侦听器添加 deep: true 
        obj: {
          handler(newVal){
            // console.log('obj改变了值是', newVal);
          },
          deep: true // 深度侦听  递归侦听
        },
        arr: {
          handler(newVal){
            console.log('arr改变了值是', newVal);
          },
          deep: true
        },
        // 对象直接侦听对象的属性
        "obj.a"(newVal){
          console.log('obj的a属性改变了', newVal);
        }
      }
    })

    app.mount('#app')
  </script>
</body>
</html>